package opentelemetry

import (
	"context"
	"go.opentelemetry.io/otel"
	"go.opentelemetry.io/otel/attribute"
	"go.opentelemetry.io/otel/trace"
	"jk-time/webook/internal/service/sms"
)

type Service struct {
	trace trace.Tracer
	svc   sms.Service
}

func NewService(svc sms.Service) sms.Service {
	tracer := otel.GetTracerProvider().Tracer("webook/internal/service/sms")
	return &Service{
		svc:   svc,
		trace: tracer,
	}
}
func (s Service) Send(ctx context.Context, biz string, args []string, numbers ...string) error {
	ctx, span := s.trace.Start(ctx, "sms_send"+biz,
		// 调用短信服务商的客户端
		trace.WithSpanKind(trace.SpanKindClient))
	defer span.End()
	span.SetAttributes(attribute.String("biz", biz))

	err := s.svc.Send(ctx, biz, args, numbers...)
	if err != nil {
		span.RecordError(err)
	}
	return nil
}
